﻿// ***********************************************************************
// Assembly         : Ls.Core
// Author           : rx.tang
// Created          : 10-23-2017
//
// Last Modified By : rx.tang
// Last Modified On : 10-23-2017
// ***********************************************************************
// <copyright file="BaseServiceUtils.cs" company="瑞新">
//     Copyright © 瑞新 2017
// </copyright>
// <summary></summary>
// ***********************************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ls.Utils;
using System.Web;
using Ls.Core.Infrastructure;
using Microsoft.AspNetCore.Http;

namespace Ls.Core
{
    public partial class BaseService : IDisposable
    {
        /// <summary>
        /// 缓存前缀
        /// </summary>
        public virtual string CacheKeyPre
        {
            get { return ""; }
        }
        /// <summary>
        /// Gets the columns.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <returns>IDictionary&lt;System.String, System.Object&gt;.</returns>
        public IDictionary<string, object> GetColumns(object obj) {
            IDictionary<string, object> columns = obj is IDictionary<string, object> ? obj as IDictionary<string, object> : obj.GetPropertiesDic();

            return columns;
        }

        public ParamBase GetParamFromForm(HttpRequest request, string id = "Id", Func<Dictionary<string, object>, bool> checkIsInsert = null) {
            return new ParamBase(request, id, checkIsInsert);
        }
        /// <summary>
        /// 清除缓存
        /// </summary>
        public void RemoveCacheByPre() {

            RemoveCacheByPre(CacheKeyPre);
        } 
        public void RemoveCacheByPre(string pre)
        { 
            if (pre.IsNotNullOrEmpty())
            {
                CacheHelper.RemoveByStartsWith(pre);
            }
        }
    }
}
